using ASP;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Shop_Manage_Shop_ViewProductByShopProductClassID : Member, IRequiresSessionState
{
	protected Label lblViewClass;
	protected TextBox TxtSreachClassName;
	protected Button btnSearch;
	protected Button btnBackList;
	protected GridView GVProduct;
	protected HtmlInputCheckBox chkAll;
	protected DropDownList DropNewClass;
	protected Button ButElite;
	protected Button ButBack;
	protected ObjectDataSource ProductDataSource;
	public int ShopID = -1;
	public int ShopProductClassID = 0;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.ShopID = base.user.ShopID;
		if (base.Request.QueryString["ShopProductClassID"] != null)
		{
			this.ShopProductClassID = int.Parse(base.Request["ShopProductClassID"].ToString());
		}
		if (!base.IsPostBack)
		{
			this.BandOldNewDropClassItem();
			this.AddOldNewDropClassItem();
			if (this.ShopProductClassID > 0)
			{
				string sql = "select ShopProductClassName from HLShop_ProductLikeCategory where ShopProductClassID=" + this.ShopProductClassID;
				DataTable dataTable = this.conn.GetDataTable(sql);
				if (dataTable.Rows.Count > 0)
				{
					if (dataTable.Columns.Contains("ShopProductClassName"))
					{
						if (dataTable.Rows[0]["ShopProductClassName"] != DBNull.Value)
						{
						}
					}
				}
			}
			this.BindClassProduct();
		}
	}
	private void BandOldNewDropClassItem()
	{
		Shop_ProductLikeCategory shop_ProductLikeCategory = new Shop_ProductLikeCategory();
		DataTable productLikeCategory = shop_ProductLikeCategory.GetProductLikeCategory(this.ShopID);
		this.DropNewClass.DataSource = productLikeCategory;
		this.DropNewClass.DataTextField = "ShopProductClassName";
		this.DropNewClass.DataValueField = "ShopProductClassID";
		this.DropNewClass.DataBind();
	}
	private void AddOldNewDropClassItem()
	{
		ListItem listItem = new ListItem();
		listItem.Text = "未分类";
		listItem.Value = "0";
		this.DropNewClass.Items.Add(listItem);
	}
	protected void BindClassProduct()
	{
		Shop_Product shop_Product = new Shop_Product();
		DataTable productByShopProductClassID = shop_Product.GetProductByShopProductClassID(this.ShopID, this.ShopProductClassID, this.TxtSreachClassName.Text);
		this.GVProduct.DataSource = productByShopProductClassID;
		this.GVProduct.DataBind();
	}
	protected void btnSearch_Click(object sender, EventArgs e)
	{
		this.BindClassProduct();
	}
	protected void btnBackList_Click(object sender, EventArgs e)
	{
		base.Response.Redirect("shop_product_category.aspx");
	}
	protected void ButElite_Click(object sender, EventArgs e)
	{
		string text = "";
		string text2 = "";
		string olarryproductid = "";
		bool flag = false;
		foreach (GridViewRow gridViewRow in this.GVProduct.Rows)
		{
			CheckBox checkBox = (CheckBox)gridViewRow.Cells[0].FindControl("CheckElite");
			if (checkBox.Checked)
			{
				text = text + this.GVProduct.DataKeys[gridViewRow.RowIndex].Value.ToString() + ",";
			}
			else
			{
				text2 = text2 + this.GVProduct.DataKeys[gridViewRow.RowIndex].Value.ToString() + ",";
			}
		}
		if (text != "")
		{
			string newarryproductid = text.Remove(text.Length - 1);
			if (text2 != "")
			{
				olarryproductid = text2.Remove(text2.Length - 1);
			}
			Shop_ProductLikeCategory shop_ProductLikeCategory = new Shop_ProductLikeCategory();
			shop_ProductLikeCategory.UpdateShopCategory(this.ShopProductClassID, int.Parse(this.DropNewClass.SelectedValue), olarryproductid, newarryproductid);
			flag = true;
		}
		if (!flag)
		{
			this.Page.Response.Write("<script>alert('请你选商品再分类')</script>");
		}
		this.BindClassProduct();
	}
	protected void ButBack_Click(object sender, EventArgs e)
	{
		base.Response.Redirect("shop_product_category.aspx");
	}
}
